emojichooser: animate the adjustment
authorBenjamin Otte <otte@redhat.com>
Sun, 5 Nov 2017 15:12:35 +0000 (16:12 +0100)
committerDaniel Boles <dboles@src.gnome.org>
Wed, 22 Nov 2017 19:11:31 +0000 (19:11 +0000)
... instead of doing a dance with the scrolled window to get it to scroll
the adjustment.

gtk/gtkemojichooser.c

index 1828b4da3dd1afaf09876636557a22524325b1d9..6a8f4359ff935fc8369e79d9604eac7f34f0f875 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "gtkemojichooser.h"
 
-#include "gtkadjustment.h"
+#include "gtkadjustmentprivate.h"
 #include "gtkbox.h"
 #include "gtkbutton.h"
 #include "gtkcssprovider.h"
@@ -62,8 +62,6 @@ struct _GtkEmojiChooser
   EmojiSection symbols;
   EmojiSection flags;
 
-  EmojiSection *scroll_to_section;
-
   GtkGesture *recent_press;
   GtkGesture *people_press;
   GtkGesture *body_press;
@@ -97,41 +95,23 @@ gtk_emoji_chooser_finalize (GObject *object)
   G_OBJECT_CLASS (gtk_emoji_chooser_parent_class)->finalize (object);
 }
 
-static gboolean
-scroll_in_idle (gpointer data)
-{
-  GtkEmojiChooser *chooser = data;
-  GtkAdjustment *adj;
-  GtkAllocation alloc = { 0, 0, 0, 0 };
-  double page_increment, value;
-  gboolean dummy;
-
-  adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
-  if (chooser->scroll_to_section->heading)
-    gtk_widget_get_allocation (chooser->scroll_to_section->heading, &alloc);
-  page_increment = gtk_adjustment_get_page_increment (adj);
-  value = gtk_adjustment_get_value (adj);
-  gtk_adjustment_set_page_increment (adj, alloc.y - value);
-  g_signal_emit_by_name (chooser->scrolled_window, "scroll-child", GTK_SCROLL_PAGE_FORWARD, FALSE, &dummy);
-  gtk_adjustment_set_page_increment (adj, page_increment);
-
-  return G_SOURCE_REMOVE;
-}
-
 static void
 scroll_to_section (GtkButton *button,
                    gpointer   data)
 {
   EmojiSection *section = data;
   GtkEmojiChooser *chooser;
+  GtkAdjustment *adj;
+  GtkAllocation alloc = { 0, 0, 0, 0 };
 
   chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_EMOJI_CHOOSER));
 
-  if (chooser->scroll_to_section == section)
-    return;
+  adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
+
+  if (section->heading)
+    gtk_widget_get_allocation (section->heading, &alloc);
 
-  chooser->scroll_to_section = section;
-  g_idle_add (scroll_in_idle, chooser);
+  gtk_adjustment_animate_to_value (adj, alloc.y);
 }
 
 static void